﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

public partial class Controls_UC_QuangCao : System.Web.UI.UserControl
{
    SqlConnection con;
    SqlDataAdapter ad;
    DataTable dt = new DataTable();
    private string Connect = ConfigurationManager.ConnectionStrings["ketnoi"].ConnectionString;
    string sql = "select TOP 6 * from QUANG_CAO order by ngay_bat_dau desc";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Hien_Thi();
        }
    }
    public void Hien_Thi()
    {
        con = new SqlConnection(Connect);
        try
        {
            con.Open();
            ad = new SqlDataAdapter(sql, con);
            ad.Fill(dt);
            if (dt.Rows.Count > 0)
            {
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }
            else
            {
                lblErr.Text = "Liên Hệ Quảng Cáo 0919751256";
            }
        }
        catch (Exception ex)
        {
            lblErr.Text = "Lỗi: " + ex.Message;
        }
        //con.Dispose();
        //ad.Dispose();
        //GridView1.Dispose();
        //con.Close();
    }

}
